import java.util.*;

/**
 * Created by qtbui on 2017/9/21.
 */

class TreeNode
{
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}

class Solution
{
    public boolean isSameTree(TreeNode p, TreeNode q)
    {
		return getTree(p).equals(getTree(q));
    }

    private String getTree(TreeNode tn)
    {
    	if(tn==null)
	    {
	    	return " ";
	    }
		String val=String.valueOf(tn.val);
		String left=getTree(tn.left);
		String right=getTree(tn.right);
		return val+left+right;
    }
}

public class test
{
    public static void main(String[] args)
    {

    }
}
